home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / PCGI.H < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-01  |  8.5 KB  |  259 lines

  1. /* pcgi.h - Persistent CGI header file for pcgi-wrapper.c, parseinfo.c
  2.  
  3. Copyright (c) 1998, Digital Creations, Fredericksburg, VA, USA.  All
  4. rights reserved. This software includes contributions from Jeff Bauer.
  5.  
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions are
  8. met:
  9.  
  10.   o Redistributions of source code must retain the above copyright
  11.     notice, this list of conditions, and the disclaimer that follows.
  12.  
  13.   o Redistributions in binary form must reproduce the above copyright
  14.     notice, this list of conditions, and the following disclaimer in
  15.     the documentation and/or other materials provided with the
  16.     distribution.
  17.  
  18.   o All advertising materials mentioning features or use of this
  19.     software must display the following acknowledgement:
  20.  
  21.       This product includes software developed by Digital Creations
  22.       and its contributors.
  23.  
  24.   o Neither the name of Digital Creations nor the names of its
  25.     contributors may be used to endorse or promote products derived
  26.     from this software without specific prior written permission.
  27.  
  28.  
  29. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS *AS IS* AND
  30. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  32. PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
  33. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  34. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  35. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  36. BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  37. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  38. OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  39. IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40.  
  41. */
  42.  
  43. #ifndef PCGI_H
  44. #include <stdlib.h>
  45. #include <stddef.h>
  46. #include <stdio.h>
  47. #include <string.h>
  48. #include <ctype.h>
  49. #include <errno.h>
  50. #include <time.h>
  51. #include <sys/types.h>
  52. #include <sys/stat.h>
  53.  
  54. #ifdef UNIX
  55. #include <unistd.h>
  56. #include <signal.h>
  57. #include <sys/wait.h>
  58. #include <sys/socket.h>
  59. #include <sys/un.h>
  60. #include <sys/ipc.h>
  61. #include <sys/sem.h>
  62. #include <netinet/in.h>
  63. #include <arpa/inet.h>
  64. #endif
  65. #ifdef WIN32
  66. #include <windows.h>
  67. #include <io.h>
  68. #include <iostream.h>
  69. #include <winsock.h>
  70. #include <fcntl.h>
  71. #endif
  72.  
  73. #define MAXLINEBUFFER   12
  74. #define PATHSEP_UNIX    '/'
  75. #define PATHSEP_WIN32   '\\'
  76. #define DEFAULT_SOCK_PORT   7244
  77. /*#define DEFAULT_SOCK_HOST "127.0.0.1"*/
  78. #define MAXPATH 1024
  79. #define PUBLISHER_NAME_1 "pcgi_publisher.py"
  80. #define PUBLISHER_NAME_2 "pcgi_publisher.pyc"
  81. #define PUBLISHER_NAME_3 "pcgi_publisher.pyo"
  82. #define PUBLISHER_NAME_4 "pcgi_publisher"
  83.  
  84. #define HDRLEN 10
  85. #define HDRFMT "%010ld"
  86.  
  87. #ifdef  UNIX
  88. #define PATHSEP PATHSEP_UNIX
  89. typedef int                     pcgi_socket;
  90. #endif
  91. #ifdef  WIN32
  92. #define PATHSEP PATHSEP_WIN32
  93. typedef SOCKET                  pcgi_socket;
  94. #define sleep(x)                Sleep(x * 1000)
  95. #define read(x,y,z)             _read(x,y,z)
  96. #define write(x,y,z)            _write(x,y,z)
  97. #define MUTEX_NAME              "pcgiMutex"
  98. #define AUTODELAY       5
  99. #define CONNRETRY       0
  100. #define CONNDELAY       1
  101. #endif
  102. #ifndef CREOSOTE
  103. /* no-op in case someone forgets to remove a spew() in their debug code */
  104. #define spew(x) 
  105. #endif
  106.  
  107. #ifndef STDIN_FILENO
  108. #define STDIN_FILENO    0
  109. #endif
  110. #ifndef STDOUT_FILENO
  111. #define STDOUT_FILENO   1
  112. #endif
  113. #ifndef STDERR_FILENO
  114. #define STDERR_FILENO   2
  115. #endif
  116.  
  117. #define MAXSZ           256
  118. #define RKEY            99
  119.  
  120. #define E_500           "500 Server Error"
  121. #define E_503           "503 Service Unavailable"
  122.  
  123. #define ERR101_FAILURE_DURING_START "(101) failure during start"
  124. #define ERR102_FAILURE_DURING_CONNECT "(102) failure during connect"
  125. #define ERR103_UNABLE_VERIFY_RUNNING "(103) unable to verify if process is running"
  126. #define ERR104_ENVIRONMENT_SEND "(104) environment send"
  127. #define ERR105_STDIN_SEND "(105) stdin send"
  128. #define ERR106_STDOUT_READ_HEADER "(106) stdout read header"
  129. #define ERR107_BAD_STDOUT_STRLEN "(107) bad stdout strlen"
  130. #define ERR108_STDOUT_READ_BODY "(108) stdout read body"
  131. #define ERR109_STDERR_READ_HEADER "(109 stderr read header"
  132. #define ERR110_BAD_STDERR_STRLEN "(110) bad stderr strlen"
  133. #define ERR111_STDERR_READ_BODY "(111) stderr read body"
  134. #define ERR112_STDOUT_TO_SERVER "(112) error returning stdout to server"
  135. #define ERR113_STDOUT_TO_SERVER "(113) error returning stderr to server"
  136. #define ERR114_UNABLE_TO_OPEN_SOCKET "(114) unable to open socket"
  137. #define ERR115_CONNECTION_REFUSED "(115) connection refused"
  138. #define ERR116_UNABLE_TO_CONNECT "(116) unable to connect"
  139. #define ERR117_LOCK_ERROR_EACCES "(117) lock error: EACCES"
  140. #define ERR118_LOCK_ERROR_EEXIST "(118) lock error: EEXIST"
  141. #define ERR119_LOCK_ERROR_EINVAL "(119) lock error: EINVAL"
  142. #define ERR120_LOCK_ERROR_ENOENT "(120) lock error: ENOENT"
  143. #define ERR121_LOCK_ERROR_ENOSPC "(121) lock error: ENOSPC"
  144. #define ERR122_LOCK_ERROR_OTHER  "(122) lock error"
  145. #define ERR123_BAD_ENV_HEADER "(123) bad environment header"
  146. #define ERR124_BAD_STDIN_HEADER "(124) bad stdin header"
  147.  
  148. /* #define onError(s,x)    {estatus=s; emsg=x; goto error;} */
  149.  
  150.  
  151. typedef struct resource_tag
  152. {  
  153.     char sw_info  [MAXSZ]; /* path to pcgi info file */
  154.     char sw_name  [MAXSZ]; /* module name */
  155.     char sw_home  [MAXSZ]; /* home path */
  156.     char sw_exe   [MAXSZ]; /* path to executable, e.g. /usr/local/bin/python */
  157.     char procpath [MAXSZ]; /* path to file containing pid */
  158.     char sockpath [MAXSZ]; /* binding path for UNIX, Win32 named pipes */
  159.     char pubpath  [MAXSZ]; /* path to pcgi_publisher.py(c) */
  160.     int  sockport;         /* port number, if INET socket */
  161.     char sockhost [MAXSZ]; /* hostname, if INET socket */
  162.     char modpath  [MAXSZ]; /* module path */
  163.     char errmsg   [MAXSZ]; /* last error, brief message */
  164.     char errlog   [MAXSZ]; /* fully qualified path to error log file */
  165.     char insertPath  [MAXPATH];  /* insert path by publisher */
  166.     char pythonPath  [MAXPATH];  /* PYTHONPATH, if provided */
  167.     short displayErrors;   /* displayErrors = 0,1 */
  168.     long sz_env;
  169.     long sz_input;
  170.     long sz_output;
  171.     long sz_error;
  172.     char *p_env;
  173.     char *p_input;
  174.     char *p_output;
  175.     char *p_error;
  176.     int  procid;
  177.     int  conn;
  178.     int  lock;
  179. } pcgiResource;
  180.  
  181. static char errorHtml[]=
  182. "Status: %s\n"
  183. "Content-Type: text/html\n"
  184. "Pragma: nocache\n"
  185. "Expires: Thu, 01 Dec 1994 16:00:00 GMT\n\n"
  186. "<HTML>\n"
  187. "<HEAD>\n"
  188. "<TITLE>Temporarily Unavailable</TITLE>\n"
  189. "</HEAD>\n"
  190. "<BODY BGCOLOR=\"#FFFFFF\">\n"
  191. "<TABLE BORDER=\"0\" WIDTH=\"100%%\">\n"
  192. "<TR>\n"
  193. "  <TD WIDTH=\"10%%\">\n"
  194. "  <CENTER>\n"
  195. "  <B><FONT SIZE=\"+6\" COLOR=\"#77003B\">!</FONT></B>\n"
  196. "  </CENTER>\n"
  197. "  </TD>\n"
  198. "  <TD WIDTH=\"90%%\"><BR>\n"
  199. "  <FONT SIZE=\"+2\">Temporarily Unavailable</FONT>\n"
  200. "  <P>\n"
  201. "  The resource you requested is temporarily unavailable - "
  202. "please try again later.\n"
  203. "  </TD>\n"
  204. "</TR>\n"
  205. "</TABLE>\n"
  206. "%s\n"
  207. "<!--\n%s\n%s\n-->\n"
  208. "</BODY></HTML>";
  209.  
  210. /* To ensure backward compatibility with pcgi info files, */
  211. /* don't change the order of the first 4 enum elements.   */
  212. enum { resource_sockpath=0,
  213.        resource_procpath=1,
  214.        resource_workdir=2,
  215.        resource_modpath=3, /* remaining elements not order dependent */
  216.        resource_sockport,
  217.        resource_sockhost,
  218.        resource_exepath,
  219.        resource_exefile,
  220.        resource_pubpath,
  221.        resource_ENUM };
  222.  
  223. /* Declarations */
  224.  
  225. void cleanup(void);
  226. void onError(char *, char *, pcgiResource *);
  227. int pcgiAssignPublisherPath(char *, pcgiResource *);
  228. int pcgiPutEnvironment(char *);
  229. long pcgiRead(pcgi_socket, char *, long);
  230. long pcgiWrite(pcgi_socket, const char *, long);
  231. int pcgiVerifyProc(pcgiResource *);
  232. pcgi_socket pcgiConnect(pcgiResource *);
  233. int pcgiStartProc(pcgiResource *);
  234. int pcgiParseInfo(pcgiResource *);
  235. int pcgiPutNameValueInEnvironment(char *, char *);
  236. void pcgiSIG(int);
  237. void pcgiPrintEnvironment();
  238. void pcgiPrintResourceInfo(pcgiResource *);
  239. int pcgiTruthValue(char);
  240. #ifdef WIN32
  241. void amendPathSeparators(char *);
  242. long pcgiReadSocket(pcgi_socket, char *, long);
  243. long pcgiWriteSocket(pcgi_socket, const char *, long);
  244. #endif
  245.  
  246. #ifdef HAVE_UNION_SEMUN
  247. #define UNION_SEMUN union semun
  248. #else
  249. #define UNION_SEMUN \
  250.     union semun { \
  251.         int val; \
  252.         struct semid_ds *buf; \
  253.         ushort *array; \
  254.     } arg;
  255. #endif
  256.  
  257. #define PCGI_H  1
  258. #endif
  259.